﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.Composition;
using Core.Interfaces;
using Core.BusinessLogic.Interfaces;
using Core.Common;
using SonCa.SocialNetwork.Web.ASCX.IPresenters;
using SonCa.SocialNetwork.Web.HelperClass;
using Core.DataAccess;

namespace SonCa.SocialNetwork.Web.ASCX.Presenters
{
    public class HeaderPresenter
    {
        private List<FriendRequestHelper> _frienRequestHelper;
        [Import]
        private IUserSession _userSession;
        [Import]
        private IAccountService _accountService;
        [Import]
        private IFriendInvitationService _friendInvitationService;
        [Import]
        private IFriendService _friendService;
        [Import]
        private IMessageService _messageService;
        [Import]
        private IMessageChatService _messageChatService;

        public void Init(IHeaderPresenter view)
        {
            MEFManager.Compose(this);
        }

        public List<FriendRequestHelper> RefreshData()
        {
            _frienRequestHelper = new List<FriendRequestHelper>();
            _accountService.GetAccountsByAccountIDList(_friendInvitationService.GetFriendsInvitationIDByBecameID(_userSession.CurrentUser.AccountID)).ForEach(n => _frienRequestHelper.Add(new FriendRequestHelper
            {
                AccountID = n.AccountID,
                FullName = n.FirstName,
                ImageUrl = string.Format("../Images/ProfileAvatar/ProfileImage.aspx?AccountID={0}", n.AccountID)
            }));
            return _frienRequestHelper;
        }

        public int CountFriendRequestInvitation()
        {
            return _friendInvitationService.CountFriendRequestInvitation(_userSession.CurrentUser.AccountID);
        }        

        public Int32 GetCurrentAccountID()
        {
            return _userSession.CurrentUser.AccountID;
        }

        public void Logout()
        {
            _accountService.Logout();
        }

        public int CountMessages()
        {
            return _messageService.CountMessages(_userSession.CurrentUser.AccountID);
        }

        public int CountMessageChat()
        {
            return _messageChatService.CountMessageChatUnReadByAccountID(_userSession.CurrentUser.AccountID);
        }
    }
}